{% extends 'base.html' %}

{% block css %}
    <link rel="stylesheet" href="static/assets/dash/AdminLTE.min.css" />
    <script src="static/assets/css/bootstrap-timepicker.css"></script>
{% endblock %}

{% block titleinfo %}

    <div class="breadcrumbs ace-save-state" id="breadcrumbs">
        <ul class="breadcrumb">
            <i class="home-icon blue" > 开发者工具 </i>
        </ul>
    </div>

{% endblock %}

{% block webinfo %}
    <div class="row">
        <div class="col-xs-12">

        {#        数据库管理设置配置界面开始#}
            <div class="col-xs-6">
                <div class="box box-danger">
                    <div class="box-header with-border">
                        <h3 class="box-title">数据库管理</h3>
                    </div>

                    <div class="box-body">
                        <div class="row">
                            <div class="col-xs-4">
                                <label>选择集合:</label>
                                <select class="form-control" id="collections_name">
                                    {% for collection in collections_names %}
                                        <option value="{{ collection }}">{{ collection }}</option>
                                    {% endfor %}
                                </select>
                                <hr>
                            </div>

                            <div class="col-xs-3">
                                <label>操作:</label>
                                <select class="form-control" id="db_command">
                                    <option value="1" >单条查询</option>
                                    <option value="2">批量查询</option>
                                    <option value="3" >删除</option>
                                    <option value="4">增加</option>
                                </select>
                                <hr>
                            </div>

                            <div class="col-xs-5">
                                <label>指定 ObjectId:</label>
                                <input type="text" class="form-control" placeholder="ObjectId" id="object_id">
                                <hr>
                            </div>

                            <hr>
                            <div class="col-xs-12">
                                <textarea class="form-control" rows="6" id="db_result"></textarea>
                                <hr>
                                <button class="btn btn-info pull-right btn-sm" id="db_management">提交更新</button>
                            </div>
                        </div>
                    </div>
                <!-- /.box-body -->
                </div>
            </div>
{#            数据库管理box结束#}


		</div><!-- #main-widget-container -->
    </div>

{% block js %}

    <script>


    jQuery(function($) {

        $('#db_management').click(function () {
            const collections_name = $('#collections_name').val();
            const db_command = $('#db_command').val();
            const object_id = $('#object_id').val();
            const data = {
                "collections_name": collections_name,
                "db_command": db_command,
                "object_id": object_id,
            };
            $.ajax({
                type: 'POST',
                url: '/dev-tools',
                dataType: 'json',
                data: data,

                success: function (data) {
                    const result_json = eval(data);
                    const result = result_json.result;
                    $('#db_result').val(result);
                    location.reload();
                },
                error: function (xhr, type) {
                }
            });
        });

        $('#port_scan_config').click(function () {
            const scan_port = $('#scan_port').val();
            const port_thread = $('#port_thread').val();
            const data = {
                "source": 'port_scan',
                "scan_port": scan_port,
                "port_thread": port_thread,
            };
            $.ajax({
                type: 'POST',
                url: '/config-change',
                dataType: 'json',
                data: data,
                success: function () {
                    alert('修改成功!');
                    location.href = "/dev-tools";
                },
                error: function () {
                    alert('修改失败!');
                }
            });
        });

        {#扫描配置#}
        $('#scanner_config').click(function () {
            const scanner_time = $('#scanner_time').val();
            const scanner_thread = $('#scanner_thread').val();
            const data = {
                "source": 'scanner_config',
                "scanner_thread": scanner_thread,
                "scanner_time": scanner_time,
            };
            $.ajax({
                type: 'POST',
                url: '/config-change',
                dataType: 'json',
                data: data,
                success: function () {
                    alert('修改成功!');
                    location.href = "/dev-tools";
                },
                error: function () {
                    alert('修改失败!');
                }
            });
        });

    });


    </script>
    <script src="static/assets/js/bootstrap-timepicker.js"></script>
{% endblock %}

{% endblock %}